<?php
/**
 * gaolei<14550209597@qq.com> 弃用
 */
namespace app\common\controller;

use app\common\model\Api as ApiModel;

class Api {
 

    protected $devToken;    //设备的tokenid
    protected $devId;       //设备的标示id
    protected $askInfo;     //请求核心内容
    protected $request;     //全部请求信息
    protected $askTime;     //当前请求时间
    protected $header;      //当前请求header
    protected $result;      //返回结果
    #信息输入
    public function __construct(\think\Request $request) {
        #初始化接口  
        $this->setHeader();
        //核心请求
        $this->request = $request;
        //请求时间
        $this->askTime= time();
        //请求header
        $this->header= $this->request->header();
        //检查客户端接口是否可接入
        $this->devId=$this->checkToken($this->header);
        if (!$this->devId) {   
            exit(Apiback($this->result=msback(100,'非法设备请求',[])));
        }
        //设备标示
        $this->devToken=$this->header['devToken'];
        //请求信息
        $this->askInfo= $this->request->param();
        
    }
    #输出结果信息
    function __destruct() {
        Apiback($this->result);
    }
    #空方法
    public function _empty() {
        return $this->result= msback(150,'请求方法错误请重试');
    }
    /**
     * 校验设备信息
     * @param type $header
     */
    protected function checkToken($header) {
        if(!empty($header['devToken'])){
            return ApiModel::checkDevToken($token);
        }
        return false;
    }

    protected function setHeader() {
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, accessToken");
    }

}
